﻿namespace STLTypeVisualizer
{
	using System;
	using VisualGDBExpressions;

	internal class GccVectorFilter : TypeListBasedExpressionFilter
	{
		static string[] textArray1 = new string[] { "std::vector<", "stlpmtx_std::vector<" };
		public GccVectorFilter() : base(textArray1)
		{
		}

		protected override IExpression DoAttach(IExpression expr, IExpressionEvaluator evaluator)
		{
			string fullNameForEvaluator = expr.FullNameForEvaluator;
			ExpressionValue value2 = evaluator.EvaluateExpression(string.Format("({0})._M_impl._M_finish-({0})._M_impl._M_start", fullNameForEvaluator), null);
			string str2 = "._M_impl";
			if (value2 == null)
			{
				value2 = evaluator.EvaluateExpression(string.Format("({0})._M_finish-({0})._M_start", fullNameForEvaluator), null);
				str2 = "";
			}
			if (!(value2 is ExpressionValue.Integral))
			{
				return null;
			}
			ulong num = (value2 as ExpressionValue.Integral).Value;
			StaticExpressionFilter filter1 = new StaticExpressionFilter(expr);
			filter1.ValueOverride = new ExpressionValue.Custom($"[{num}个元素]");
			VirtualExpressionNode node1 = new VirtualExpressionNode("[实际成员]", "", expr.Children);
			node1.FixedValue = new ExpressionValue.Composite("{...}");
			VirtualExpressionNode actualMembersNode = node1;
			filter1.ChildrenOverride = new ArrayChildProvider(evaluator, string.Format("({0}){2}._M_start[{1}]", fullNameForEvaluator, "{0}", str2), 0, (int)num, actualMembersNode);
			return filter1;
		}
	}

	internal class ClangVectorFilter : TypeListBasedExpressionFilter
	{
		static string[] textArray1 = new string[] { "std::__1::vector<" };
		public ClangVectorFilter() : base(textArray1)
		{
		}

		protected override IExpression DoAttach(IExpression expr, IExpressionEvaluator evaluator)
		{
			string fullNameForEvaluator = expr.FullNameForEvaluator;
			ExpressionValue value2 = evaluator.EvaluateExpression(string.Format("({0}).__end_-({0}).__begin_", fullNameForEvaluator), null);
			if (value2 == null)
			{
				value2 = evaluator.EvaluateExpression(string.Format("({0}).__end_-({0}).__begin_", fullNameForEvaluator), null);
			}
			if (!(value2 is ExpressionValue.Integral))
			{
				return null;
			}
			ulong num = (value2 as ExpressionValue.Integral).Value;
			StaticExpressionFilter filter1 = new StaticExpressionFilter(expr);
			filter1.ValueOverride = new ExpressionValue.Custom($"[{num}个元素]");
			VirtualExpressionNode node1 = new VirtualExpressionNode("[实际成员]", "", expr.Children);
			node1.FixedValue = new ExpressionValue.Composite("{...}");
			VirtualExpressionNode actualMembersNode = node1;
			filter1.ChildrenOverride = new ArrayChildProvider(evaluator, string.Format("({0}).__begin_[{1}]", fullNameForEvaluator, "{0}"), 0, (int)num, actualMembersNode);
			return filter1;
		}
	}
}

